package org.minproject.my_library_back.controller;

import jakarta.annotation.Resource;
import org.minproject.my_library_back.common.CommonResponse;
import org.minproject.my_library_back.domain.Borrow;
import org.minproject.my_library_back.service.BorrowService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class BorrowController {
    @Resource
    private BorrowService borrowService;

    @GetMapping("/borrows")
    public CommonResponse<List<Borrow>> getBorrows() throws Exception {
        return borrowService.getBorrows();
    }

    @GetMapping("/borrows/{userid}")
    public CommonResponse<List<Borrow>> getBorrowsByUserid(@PathVariable("userid") int userid) throws Exception {
        return borrowService.getBorrowsByUserid(userid);
    }

    @PostMapping("/borrows")
    public CommonResponse<Borrow> addBorrow(@RequestBody Borrow borrow) throws Exception {
        return borrowService.addBorrow(borrow);
    }

    @PostMapping("/borrows/delete")
    public CommonResponse<Borrow> deleteBorrow(@RequestBody Borrow borrow) throws Exception {
        return borrowService.deleteBorrow(borrow);
    }

    @PostMapping("/borrows/return")
    public CommonResponse<Borrow> returnBorrow(@RequestBody Borrow borrow) throws Exception {
        return borrowService.returnBorrow(borrow);
    }
}
